package logic

import (
	"context"
	"fmt"
	"user_center/models/mysql"

	"user_center/userrpc/internal/svc"
	"user_center/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserShowLogic {
	return &UserShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 用户详情
func (l *UserShowLogic) UserShow(in *userrpc.UserShowRequest) (*userrpc.UserShowResponse, error) {
	// todo: add your logic here and delete this line
	var user mysql.User
	mysql.DB.Debug().Where("id = ?", in.Id).Find(&user)
	if user.ID == 0 {
		return nil, fmt.Errorf("当前用户不存在，无法查看详情")
	}
	return &userrpc.UserShowResponse{
		Name:    user.Name,
		Sex:     user.Sex,
		Address: user.Address,
		Email:   user.Email,
	}, nil
}
